package com.itstudy.study.student.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itstudy.study.response.R;
import com.itstudy.study.student.entity.Student;
import com.itstudy.study.student.pojo.request.StudentRequest;
import com.itstudy.study.student.service.StudentService;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chenxiaofan
 */
@RestController
public class StudentController {

    @Resource
    private StudentService studentService;

    @GetMapping(name = "获取学生列表", path = "/student/list")
    public R list(StudentRequest request) {
        List<Student> list = studentService.list(request);
        return new R(list);
    }

    @GetMapping(name = "获取学生分页列表", path = "/student/page")
    public R page(StudentRequest request) {
        Page<Student> page = studentService.page(request);
        return new R(page);
    }

    @PostMapping(name = "获取学生分页列表", path = "/student/add")
    public R add(@RequestBody StudentRequest request) {
        R r = studentService.add(request);
        return r;
    }

    @GetMapping(name = "获取学生分页列表", path = "/student/getStudentByCode")
    public R getStudentByCode(StudentRequest request) {
        Student student = studentService.getStudentByCode(request);
        return new R(student);
    }
}
